import os  
from pathlib import Path  
  
def find_executable_files(directory):  
    """  
    Find all executable files without extensions in a directory and its subdirectories.  
    """  
    executable_files = []  
    for root, dirs, files in os.walk(directory):  
        for file in files:  
            if not file.split('.')[-1] and os.access(os.path.join(root, file), os.X_OK):  
                print("write file is " + file)
                executable_files.append(os.path.relpath(os.path.join(root, file), directory))  
    return executable_files  
  
def write_to_gitignore(files, gitignore_path):  
    """  
    Write the list of files to a .gitignore file.  
    """  
    with open(gitignore_path, 'a') as f:  
        for file in files:  
            f.write(file + '\n')  
  
# Main program  
if __name__ == "__main__":  
    current_directory = Path.cwd()  # Get the current working directory  
    executable_files = find_executable_files(str(current_directory))  
    gitignore_path = current_directory / ".gitignore"  
  
    if gitignore_path.exists():  
        print(f"The .gitignore file already exists. You may want to backup it before continuing.")  
        confirm = input("Do you want to overwrite the existing .gitignore file? (yes/no): ")  
        if confirm.lower() != 'yes':  
            print("Exiting program.")  
            exit()  
  
    write_to_gitignore(executable_files, str(gitignore_path))  
    print(f"Wrote {len(executable_files)} executable files to .gitignore.")
